package demo5;

import demo2.Emp;

import java.util.HashMap;
import java.util.Map;

public class TestMap {
    public static void addEmp(Map<String, Emp> map, Emp emp) {
    map.put(emp.getNumber(), emp);
}


    public void findAllEmp(Map<String, Emp> map) {
        for (Emp emp : map.values()) {
            System.out.println(emp);
        }
    }


    public Emp findEmpName(Map<String, Emp> map, String name) {
        for (Emp emp : map.values()) {
            if (emp.getName().equals(name)) {
                return emp;
            }
        }
        return null;
    }


    public void deleteEmp(Map<String, Emp> map, String number) {
        map.remove(number);
    }

    public Emp findEmpNumber(Map<String, Emp> map, String number) {
        return map.get(number);
    }

    public void changeEmpAge(Map<String, Emp> map, String number, int age) {
        Emp emp = map.get(number);
        if (emp != null) {
            emp.setAge(age);
        } else {
            System.out.println("未找到该员工编号对应的员工");
        }
    }
}